←Select platform

UserFilterCommand Constructor(int,int,LeadPoint,int,int,UserFilterCommandType,int[])

Summary
Initializes a new UserFilterCommand class object with explicit parameters.
Syntax
C#
Objective-C
C++/CLI
Java
Python
- (instancetype)initWithFilterWidth:(NSUInteger)filterWidth filterHeight:(NSUInteger)filterHeight centerPoint:(LeadPoint)centerPoint divisor:(NSUInteger)divisor offset:(NSInteger)offset type:(LTUserFilterCommandType)type matrix:(NSArray<NSNumber *> *)matrix NS_DESIGNATED_INITIALIZER; 
public UserFilterCommand( 
   int filterWidth, 
   int filterHeight, 
   LeadPoint centerPoint, 
   int divisor, 
   int offset, 
   UserFilterCommandType type, 
   int[] matrix 
); 
public: 
UserFilterCommand(  
   int filterWidth, 
   int filterHeight, 
   LeadPoint centerPoint, 
   int divisor, 
   int offset, 
   UserFilterCommandType type, 
   array<int>^ matrix 
) 
__init__(self,filterWidth,filterHeight,centerPoint,divisor,offset,type,matrix) # Overloaded constructor 

Parameters

filterWidth
Number of columns in the user-defined array (mask). This parameter only accepts positive values.

filterHeight
Number of rows in the user-defined array (mask). This parameter only accepts positive values.

centerPoint
Any two-dimensional position of the matrix array, to be used as the matrix (mask)center.

divisor
Value used to divide the final result of the output. This must be a non-zero value. If you want to use floating point values for the matrix elements and the divisor, multiply the matrix elements and the divisor with the same value (for example, 10, 100, 1000). This parameter only accepts positive values.

offset
Value used to offset the final result of the output.

type
Flag that indicates the type of operation.

matrix
Array of (filterWidth * filterHeight) integers containing the user-defined matrix (mask). The elements are stored in row order (first row, second row, etc).

Example

Run the UserFilterCommand on an image, In this example the high pass.filter will be applied using user defined matrix.

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing.Effects; 
 
 
public void UserFilterConstructorExample() 
{ 
   // Load an image 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP")); 
 
   // Prepare the command 
   int[] matrix = new int[9]; 
 
   // Initialize the array with factor used to apply the high pass filter. 
   for (int i = 0; i < 3; i++) 
   { 
      for (int j = 0; j < 3; j++) 
      { 
         if (j == 1 || i == 1) 
         { 
            if (j == 1 && i == 1) 
               matrix[i * 3 + j] = 5; 
            else 
               matrix[i * 3 + j] = -1; 
         } 
         else 
            matrix[i * 3 + j] = 0; 
      } 
   } 
 
   UserFilterCommand command = new UserFilterCommand(3, 3, new LeadPoint(1, 1), 1, 0, UserFilterCommandType.Sum, matrix); 
   // Apply the high pass custom filter. 
   command.Run(image); 
 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.imageprocessing.effects.UserFilterCommand; 
import leadtools.imageprocessing.effects.UserFilterCommandType; 
 
 
public void userFilterConstructorExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
 
   // Load an image 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.setThrowExceptionsOnInvalidImages(true); 
 
   RasterImage image = codecs.load(combine(LEAD_VARS_IMAGES_DIR, "IMAGE1.CMP")); 
 
   // Prepare the command 
   int[] matrix = new int[9]; 
 
   // Initialize the array with factor used to apply the high pass filter. 
   for (int i = 0; i < 3; i++) { 
      for (int j = 0; j < 3; j++) { 
         if (j == 1 || i == 1) { 
            if (j == 1 && i == 1) 
               matrix[i * 3 + j] = 5; 
            else 
               matrix[i * 3 + j] = -1; 
         } else 
            matrix[i * 3 + j] = 0; 
      } 
   } 
   UserFilterCommand command = new UserFilterCommand(3, 3, new LeadPoint(1, 1), 1, 0, UserFilterCommandType.SUM, 
         matrix); 
 
   // Apply the high pass custom filter. 
   int change = command.run(image); 
   assertTrue(change != RasterImageChangedFlags.NONE); 
 
   codecs.save(image, combine(LEAD_VARS_IMAGES_DIR, "Result.jpg"), RasterImageFormat.JPEG, 24); 
   System.out.println("Command run and image saved to " + combine(LEAD_VARS_IMAGES_DIR, "Result.jpg")); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.3.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.ImageProcessing.Effects Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.